package cn.njxzc.exercises;

import java.io.*;
import java.util.*;

class MyTimer {
	private final long start;

	public MyTimer() {
		start = System.currentTimeMillis();
	}

	public long getElapsed() {
		return System.currentTimeMillis() - start;
	}
}

public class IoDemo {
	@SuppressWarnings("unchecked")
	static void getFileList2(File f, List list) {
		if (f.isDirectory()) {
			String entries[] = f.list();
			int maxlen = (entries == null ? 0 : entries.length);
			for (int i = 0; i < maxlen; i++) {
				getFileList2(new File(f, entries[i]), list);
			}
		} else if (f.isFile()) {
			list.add(f.getPath());
			System.out.println(list);
		}
	}

	@SuppressWarnings("rawtypes")
	static List getFileList(String fn) {
		List list = new ArrayList();
		getFileList2(new File(fn), list);
		return list;

	}

	@SuppressWarnings("rawtypes")
	public static void main(String[] args) {
		MyTimer mt = new MyTimer();
		//List list = getFileList(args[0]);
		List list = getFileList("f:\\temp");
		System.out.println("number of files = " + list.size());
		System.out.println("microseconds per file = " + mt.getElapsed() * 1000
				/ list.size());

	}

}
